package com.manage.web;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.util.AJAXResultMessage;
import com.common.util.ExtjsPageable;
import com.manage.entity.TrainingCourse;
import com.manage.service.ITrainingCourseService;
import com.syslog.aop.SystemServiceLog;


@Controller
@RequestMapping(value="/trainingCourse")
public class TrainingCourseController 
{
	@Autowired
	private ITrainingCourseService trainingCourseService;
	
	@SystemServiceLog("保存或修改培训课程")
	@RequestMapping(value="/saveOrUpdate")
	public @ResponseBody AJAXResultMessage saveOrUpdate(TrainingCourse trainingCourse) 
	{
		try {
			trainingCourseService.saveOrUpdate(trainingCourse);
    		return new AJAXResultMessage(true,"操作成功!");
	    } catch (Exception e) {
	    	e.printStackTrace();
	        return new AJAXResultMessage(false,"操作失败!");
	    }
	}
	@SystemServiceLog("删除培训课程")
	@RequestMapping(value = "/deleteTrainingCourses")
    public @ResponseBody AJAXResultMessage delete(Long[] ids) {
    	try {
    		List<Long> idlists=Arrays.asList(ids);
    		if(null!=idlists) {
    			trainingCourseService.delete(idlists);
    		}    		
    		return new AJAXResultMessage(true,"操作成功!");
	    } catch (Exception e) {
	    	e.printStackTrace();
	        return new AJAXResultMessage(false,"操作失败!");
	    }
    }
	@SystemServiceLog("删除培训课程")
	@RequestMapping(value = "/delete")
    public @ResponseBody AJAXResultMessage delete(Long id) {
    	try {
    		trainingCourseService.delete(id);
    		return new AJAXResultMessage(true,"操作成功!");
	    } catch (Exception e) {
	    	e.printStackTrace();
	        return new AJAXResultMessage(false,"操作失败!");
	    }
    }
//	@RequestMapping("/findOne")
//	public @ResponseBody CourseDTO findOne(Long id) {
//		return courseService.findOne(id);
//	}
	
	@SystemServiceLog("查询培训课程")
	@RequestMapping("/findPage")
	public @ResponseBody Page<TrainingCourse> findAll(TrainingCourse trainingCourse,ExtjsPageable pageable) 
	{
		 Page<TrainingCourse> page =trainingCourseService.findAll(trainingCourse, pageable.getPageable());		
		 return page;
	}

}
